<?php

	// TITLE: Event_expense AUTO MODEL
	// FILE: scaffolding/model/event_expense.php
	// AUTHOR: AUTOGEN
	// CREATED: 2015/04/20 07:49:57
	// DESCRIPTION: 
	// REQUIREMENTS: 

	$createEventExpense = function($con, $eventExpense) {
		$sql = 'INSERT INTO event_expense (id, event_id, title, description, amount, who_entered, when_entered, who_authorized, when_authorized) VALUES (';
		$sql .= $event_expense->getId() . ', ';
		$sql .= $event_expense->getEventId() . ', ';
		$sql .= $event_expense->getTitle() . ', ';
		$sql .= $event_expense->getDescription() . ', ';
		$sql .= $event_expense->getAmount() . ', ';
		$sql .= $event_expense->getWhoEntered() . ', ';
		$sql .= $event_expense->getWhenEntered() . ', ';
		$sql .= $event_expense->getWhoAuthorized() . ', ';
		$sql .= $event_expense->getWhenAuthorized() . ')';
		$sql .= ')';
		$result = mysqli_query($con, $sql);
		$id = ($result) ? mysqli_insert_id($con) : $result;
		mysqli_close($con);
		return $id;
	};

	$readEventExpense = function($con, $id) {
		$sql = 'SELECT * FROM event_expense WHERE id = ' . $id;
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$result = mysqli_fetch_array($results);
			$eventExpense = new EventExpense();
			$eventExpense->setId(result[0]);
			$eventExpense->setEventId($dbio->select($readEvent(result[1])));
			$eventExpense->setTitle(result[2]);
			$eventExpense->setDescription(result[3]);
			$eventExpense->setAmount(result[4]);
			$eventExpense->setWhoEntered(result[5]);
			$eventExpense->setWhenEntered(result[6]);
			$eventExpense->setWhoAuthorized(result[7]);
			$eventExpense->setWhenAuthorized(result[8]);
		} else {
			$eventExpense = false;
		}
		return $eventExpense;
	};

	$updateEventExpense = function($con, $eventExpense) {
		$sql = 'UPDATE event_expense SET ';
		$sql .= 'id = ' . $event_expense->getId() . ', ';
		$sql .= 'event_id = ' . $event_expense->getEventId() . ', ';
		$sql .= 'title = ' . $event_expense->getTitle() . ', ';
		$sql .= 'description = ' . $event_expense->getDescription() . ', ';
		$sql .= 'amount = ' . $event_expense->getAmount() . ', ';
		$sql .= 'who_entered = ' . $event_expense->getWhoEntered() . ', ';
		$sql .= 'when_entered = ' . $event_expense->getWhenEntered() . ', ';
		$sql .= 'who_authorized = ' . $event_expense->getWhoAuthorized() . ', ';
		$sql .= 'when_authorized = ' . $event_expense->getWhenAuthorized() ;
		$sql .= 'WHERE id = ' . id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$deleteEventExpense = function($con, $id) {
		$sql = 'DELETE FROM event_expense WHERE id = ' . $id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$listEventExpense = function($con) {
		$sql = 'SELECT * FROM event_expense';
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$eventExpenses = array();
			while ($result = mysqli_fetch_array($results)) {
				$eventExpense = new EventExpense();
				$eventExpense->setId(result[0]);
				$eventExpense->setEventId($dbio->select($readEvent(result[1])));
				$eventExpense->setTitle(result[2]);
				$eventExpense->setDescription(result[3]);
				$eventExpense->setAmount(result[4]);
				$eventExpense->setWhoEntered(result[5]);
				$eventExpense->setWhenEntered(result[6]);
				$eventExpense->setWhoAuthorized(result[7]);
				$eventExpense->setWhenAuthorized(result[8]);
				$eventExpenses[] = eventExpense;
			}// end while
		} else {
			$eventExpenses = false;
		}
		return $eventExpenses;
	};

